package com.wgj.android.dialog;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatDialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.jiaai.xui.XUI;
import com.jiaai.xui.utils.XDensityUtils;
import com.wgj.android.R;
import com.wgj.android.http.WGJAPI;
import com.wgj.android.ui.activity.QuestionActivity;
import com.wgj.android.utils.CacheUtils;
import com.wgj.android.web.WGJWebActivity;
import com.wgj.android.web.entity.WebConfig;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/18.
 */

public class ShengNanNvDiadlog  extends AppCompatDialogFragment{
    private Dialog dialog;
    private View view;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(view==null){
            super.onCreate(savedInstanceState);
            view = LayoutInflater.from(getActivity()).inflate(R.layout.sheng_nannv_diadlog, null, false);
        }
        ButterKnife.bind(this,view);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
       if(dialog==null){
            initDialogStyle(view);
       }
       return  dialog;
    }


    private void initDialogStyle(View view) {
        dialog = new Dialog(getActivity(), R.style.dialog_setting);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Content前设定

        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(false); // 外部点击取消
        // 设置宽度为屏宽, 靠近屏幕底部。
        Window window = dialog.getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.CENTER; // 紧贴底部
        lp.width =WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    @OnClick(R.id.close) void  onCloseClick(View view){
        dismiss();
    }

    @OnClick(R.id.start) void  onStart(View view){
        WebConfig webConfig=new WebConfig(WGJAPI.BASEURL+"page/havebaby/"+ CacheUtils.getMember().getM_id(),"生男生女",0);
        Intent intent=new Intent(getContext(), WGJWebActivity.class);
        Bundle bundle=new Bundle();
        bundle.putSerializable(WGJWebActivity.WEB_CONFIG,webConfig);
        intent.putExtras(bundle);
       // Intent intent=new Intent(getContext(),QuestionActivity.class);
        startActivity(intent);
        dismiss();
    }


}
